<template>
    <div class="add-applet-main">
        <div class="item-info">
            <img class="img-icon" src="@/assets/channelConfig/marketingApplet/icon_img_01.png" alt="" />
            <div class="info-title">已有微信小程序</div>
            <div class="info-btn" @click="onAuthorizerNow">立即授权</div>
        </div>
        <div class="item-info">
            <img class="img-icon" src="@/assets/channelConfig/marketingApplet/icon_img_01.png" alt="" />
            <div class="info-title">没有微信小程序</div>
            <div class="info-btn" @click="onRegisterNow">立即注册</div>
        </div>
    </div>
    <AppletDialog ref="appletDialogRef" />
</template>
<script setup lang="ts">
import AppletDialog from './appletDialog.vue';
import { ref, reactive } from 'vue';
import { getInstallLink } from '@/api/channelconfig/marketingApplet';

const props = defineProps({
    programType: {
        type: [String, Number],
        default: 1
    }
});

const appletDialogRef = ref<any>(null);

const onAuthorizerNow = async () => {
    const params = {
        callback_front_url: 'https://' + window.location.host + '/redirect-info-guide',
        auth_type: 2,
        mini_program_type: props.programType
    };
    const res = await getInstallLink(params);
    if (res.url) {
        window.open(res.url, '_blank');
    }
};

const onRegisterNow = () => {
    appletDialogRef.value.appDialog.mini_program_type = props.programType;
    appletDialogRef.value.appDialog.visible = true;
};
</script>
<style lang="scss" scoped>
.add-applet-main {
    display: flex;
    justify-content: space-between;
    .item-info {
        padding: 44px 0;
        width: 400px;
        background: #ffffff;
        box-shadow: 0px 2px 24px 0px #eaeaea;
        border-radius: 4px;
        text-align: center;
        .img-icon {
            width: 60px;
            height: 60px;
        }
        .info-title {
            padding-top: 32px;
            font-size: 16px;
            line-height: 24px;
        }
        .info-btn {
            cursor: pointer;
            color: #ff6b00;
            font-size: 16px;
            line-height: 24px;
            text-decoration: underline;
        }
    }
}
</style>
